/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import MaDictRadio from "@/components/ma-dict-picker/ma-dict-radio.vue";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import MaUploadImage from "@/components/ma-upload-image/index.vue";
import {
  spotStatus,
  showType,
} from "$/attractions/attraction-management/views/attractionSpot/data/common.tsx";
import { getAll as getTypeList } from "$/attractions/attraction-management/api/attractionType.ts";
import { getAll as getPositionList } from "$/attractions/attraction-management/api/attractionSpotPosition.ts";
import { getAll as getAttractionList } from "$/attractions/attraction-management/api/attraction.ts";
import { pageAll as getCameraList } from "$/gq/video-monitoring/api/gqVideoCamera.ts";
import MaWangEditor from "$/attractions/attraction-management/components/MaWangEditor.vue";
import { concat } from "lodash-es";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "点位名称",
      prop: "name",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "点位名称" }) },
      itemProps: { rules: [{ required: true, message: "请输入点位名称" }] },
    },
    {
      label: "位置",
      prop: "position_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getPositionList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.name || `位置${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择位置",
        clearable: true,
      },
      itemProps: {
        rules: [{ required: true, message: "请选择位置" }],
      },
    },
    {
      label: "点位类型",
      prop: "type_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getTypeList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            // 过滤type为1的数据（点位类型）
            return response.data.list
              .filter((item: any) => item.type === 1)
              .map((item: any) => ({
                label: item.name,
                value: item.id,
              }));
          }
          return [];
        },
        placeholder: "请选择点位类型",
        clearable: true,
      },
      itemProps: {
        rules: [{ required: true, message: "请选择点位类型" }],
      },
    },
    {
      label: "关联摄像头",
      prop: "extension",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getCameraList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            // 过滤type为1的数据（点位类型）
            return response.data.list.map((item: any) => ({
              label: item.name,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择关联摄像头",
        clearable: true,
      },
    },
    {
      label: "点位标题",
      prop: "intro_title",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "点位介绍标题" }),
      },
      itemProps: { rules: [{ required: true, message: "请输入点位介绍标题" }] },
    },
    {
      label: "点位介绍",
      prop: "intro",
      render: () => MaWangEditor,
      renderProps: {
        height: 400,
        placeholder: "请输入点位介绍...",
      },
    },
    {
      label: "所属景区",
      prop: "attraction_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getAttractionList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.name || `景区${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择所属景区",
        clearable: true,
      },
      itemProps: {
        rules: [{ required: true, message: "请选择所属景区" }],
      },
    },
    {
      label: "点位封面",
      prop: "cover_id",
      render: () => MaUploadImage,
      renderProps: { multiple: false },
    },
    {
      label: "显示类型",
      prop: "show_type",
      render: () => MaDictRadio,
      renderProps: {
        placeholder: t("form.pleaseInput", {
          msg: "显示类型1:管理端显示2:管理游客双端显示",
        }),
        data: showType,
      },
      itemProps: { rules: [{ required: true, message: "请选择显示类型" }] },
    },
    {
      label: "点位图标",
      prop: "icon_id",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "点位图标" }) },
    },
    {
      label: "点位状态",
      prop: "status",
      render: () => MaDictRadio,
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "点位状态1:禁用2:正常" }),
        data: spotStatus,
      },
      itemProps: { rules: [{ required: true, message: "请输入点位状态" }] },
    },
    {
      label: "点位排序",
      prop: "sort",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "点位排序" }) },
      itemProps: { rules: [{ required: true, message: "请输入点位排序" }] },
    },
  ]);
}
